package epucjr.psicopuc.teste.testeDemoTableButton;

import epucjr.psicopuc.view.componentes.TableButtonRenderer;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

public class DemoTableButton extends JFrame
implements EmployeeTableModel.EmployeeButtonHandler
{
	private JLabel messageLabel;

	public static void main(String[] args)
	{
		new DemoTableButton();
	}

	public DemoTableButton()
	{
		setLayout(new BorderLayout());

		messageLabel = new JLabel("Click a button.");
		add(messageLabel, BorderLayout.NORTH);

		// create the table and the model
		EmployeeTableModel model = new EmployeeTableModel(this);
		JTable table = new JTable(model);
		// now make a renderer the default for columns of type JButton
		TableButtonRenderer renderer = new TableButtonRenderer();
		table.setDefaultEditor(JButton.class, renderer);
		table.setDefaultRenderer(JButton.class, renderer);
                table.getColumnModel().getColumn(0).setResizable(false);
                table.getColumnModel().getColumn(0).setPreferredWidth(200);
		// add the table in a scrollpane
		JScrollPane scroll = new JScrollPane(table);
		add(scroll, BorderLayout.CENTER);

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		SwingUtilities.invokeLater(new Runnable() {
			public void run()
			{
				setVisible(true);
				setSize(400, 300);
			}
		});
	}

	public void buttonClicked(Employee e)
	{
		messageLabel.setText("Full Name: " + e.getName() + " " + e.getSurname());
	}
}